import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import './MovieDetail.dart';

class MoviePage extends StatelessWidget {

  final List movielist = [
    {'name': '攀登者', 'img': 'https://p0.meituan.net/170.230/movie/4c01895cfd53e82f7c3048c407974a6b4739229.jpg'},
    {'name': '诛仙', 'img': 'https://p0.meituan.net/170.230/movie/845dce25ba800e91ac591b683a0c3ba92450317.jpg'},
    {'name': '小小的愿望', 'img': 'https://p0.meituan.net/170.230/movie/d18915868f6e3e6e287162354700690f2338229.jpg'},
    {'name': '中国机长', 'img': 'https://p0.meituan.net/170.230/moviemachine/4de45617746dae456738bc322670cb88562422.jpg'},
    {'name': '罗小黑战记', 'img': 'https://p0.meituan.net/170.230/movie/0772ff70aafc57e0005535d4d7c93b112720771.jpg'},
    {'name': '名侦探柯南', 'img': 'https://p0.meituan.net/170.230/moviemachine/b7362f555340906684944957dfc8d5421530646.jpg'},
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("电影主页"),
      ),
      body: Container(
        height: 238,
        child: ListView.builder(
          scrollDirection: Axis.horizontal,
          itemCount: movielist.length,
          itemBuilder: (BuildContext context, int i){
            var myitem = movielist[i];
            return _ImgItem(name: myitem['name'], img: myitem['img'],);
          },
        ),
      ),
    );
  }
}

class _ImgItem extends StatelessWidget {

  _ImgItem({Key key, @required this.name, @required this.img}):super(key: key);
  final String name;
  final String img;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        width: 170,
        margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
        child: Image.network(
          '$img',
          fit: BoxFit.cover,
        ),
      ),
      onTap: () {
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (BuildContext context) {
          return MovieDetail(
            name: '$name',
            img: '$img',
          );
        }));
      },
    );
  }
}
